import React, { Component } from 'react'
import { Button } from 'antd'

// 1. 创建上下文
const Context = React.createContext()

const store = {
    'name': '开课吧',
    sayHi() {
        console.log(this.name)
    }
}

export default class ContextCont extends Component {
    render() {
        return (
            <div>
                <Context.Provider value={store}>
                    <div>
                        {/* 获取数据 */}
                        <Context.Consumer>
                            {/* 必须内嵌一个函数 */}
                            {value => <div onClick={() => value.sayHi()}>
                                {value.name}
                            </div>}
                        </Context.Consumer>
                    </div>
                </Context.Provider>
            </div>
        )
    }
}
